package com.cskaoyan.day9;

import java.util.Scanner;

public class AccountTest {
    public static void main(String[] args) {
        Account account = new Account();
        System.out.println("请输入账号:");
        while (true) {
            Scanner sc = new Scanner(System.in);
            String username = sc.nextLine();
            if (account.setUserName(username)) {
                break;
            }
        }
        System.out.println("请输入密码:");
        while (true) {
            Scanner sc = new Scanner(System.in);
            String password = sc.nextLine();
            if (account.setPassword(password)) {
                break;
            }
        }
        System.out.println("请输入存款金额:");
        while (true) {
            Scanner sc = new Scanner(System.in);
            String balance = sc.nextLine();
            if (account.setBalance(Double.parseDouble(balance))) {
                break;
            }
        }
        System.out.println(account.toString());
    }
}

class Account {
    private String userName;
    private String password;
    private double balance;

    public String getUserName() {
        return userName;
    }

    public boolean setUserName(String userName) {
        if (userName.length() < 4 || userName.length() > 6) {
            System.out.println("要求用户名长度4-6位,请重新输入");
            return false;
        }
        this.userName = userName;
        return true;
    }

    public String getPassword() {
        return password;
    }

    public boolean setPassword(String password) {
        if (password.length() != 6) {
            System.out.println("要求密码长度6位,请重新输入");
            return false;
        }
        this.password = password;
        return true;
    }

    public double getBalance() {
        return balance;
    }

    public boolean setBalance(double balance) {
        if (balance <= 100) {
            System.out.println("要求金额必须大于100,请重新输入");
            return false;
        }
        this.balance = balance;
        return true;
    }

    @Override
    public String toString() {
        return "Account{" +
                "userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", balance=" + balance +
                '}';
    }
}
